<%--
  Created by IntelliJ IDEA.
  User: cyy
  Date: 2022/12/5
  Time: 14:15
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.cyy.bean.product" %>
<%@ page import="java.util.ArrayList" %>
<%@ taglib prefix="rapid" uri="http://www.rapid-framework.org.cn/rapid" %>
<!DOCTYPE html>
<html>
<head>
    <title>商城后台</title>
</head>
<body>
    <%--添加失败时的提示框--%>
    <%
        Object message=request.getAttribute("message");
        if(message!=null&&!"".equals(message))
        {%>
    <script type="text/javascript">
        alert("<%=message%>");
    </script>
    <%}%>
    <rapid:override name="menuContent">
        <div class="nav" style="display: inline;">
            <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
                <div class="container-fluid">
                    <div class="collapse navbar-collapse" id="navbarNavDropdown">
                        <div class="collapse navbar-collapse justify-content-between" id="navbarCollapse">
                            <div class="navbar-nav col-ml-6">
                                <a class="nav-item nav-link" onclick="reShow()">商品目录</a>
                                <a class="nav-item nav-link" onclick="showUserHistory()">用户购买日志</a>
                            </div>
                            <div class="navbar-nav col-ml-6">
                                <div class="navbar-nav ml-auto">
                                    <div class="nav-item dropdown">
                                        <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown">我的账户 <%=session.getAttribute("name")%></a>
                                        <div class="dropdown-menu">
                                            <a href="#" class="dropdown-item" onclick="logout()">注销</a>
                                            <a href="#" class="dropdown-item" onclick="show1()">我的个人信息</a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </nav>
        </div>
    </rapid:override>
    <rapid:override name="mainContent">
        <div class="cart-page" align="center">
            <div class="container-fluid">
                <div class="row" >
                    <div class="col-md-2"></div>
                    <div class="col-md-8">
                        <div class="cart-page-inner">
                            <div class="table-responsive">
                                <table class="table table-bordered" id="tableSort">
                                    <thead class="thead-dark">
                                    <tr>
                                        <th id="th0" onclick="tablesort('tableSort',0)">商品名<i class="iconfont icon-shangxiajiantou"></i></th>
                                        <th id="th1" onclick="tablesort('tableSort',1)">单价<i class="iconfont icon-shangxiajiantou"></i></th>
                                        <th id="th2" onclick="tablesort('tableSort',2)">已售<i class="iconfont icon-shangxiajiantou"></i></th>
                                        <th id="th3" onclick="tablesort('tableSort',3)">库存<i class="iconfont icon-shangxiajiantou"></i></th>
                                        <th id="th4">删除</th>
                                        <th id="th5">修改单价/库存</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <%
                                        ArrayList<product> products=(ArrayList<product>)session.getAttribute("products");
                                        if(products!=null)
                                        {
                                            for (int i=0;i<products.size();i++) {
                                            String id0="td0_"+i;
                                            String id1="td1_"+i;
                                            String id2="td2_"+i;
                                            String id3="td3_"+i;
                                            String bt_id1="modifyBt_"+i;
                                            String bt_id2="commitBt_"+i;
                                            String bt_id3="cancelBt_"+i;
                                    %>
                                    <script>
                                        document.getElementById("lineNum").value=<%=products.size()%>;
                                    </script>
                                    <tr>
                                        <%if(i!=products.size()){%>
                                        <td id=<%=id0%>><%=products.get(i).getName()%></td>
                                        <td id=<%=id1%>> <%=products.get(i).getPrice()%></td>
                                        <td id=<%=id2%>><%=products.get(i).getSold()%></td>
                                        <td id=<%=id3%>> <%=products.get(i).getReserve()%></td>
                                        <td>
                                            <a href="/deleteProduct?&productId=<%=products.get(i).getId()%>"><i class="fa fa-trash"></i></a>
                                        </td>
                                        <td id="bts">
                                            <button id=<%=bt_id1%> style="display:inline-block" onclick="editProduct(<%=i%>,<%=products.get(i).getPrice()%>,<%=products.get(i).getReserve()%>)">
                                                <i class="fa fa-edit" style="color: #17a2b8"></i>
                                            </button>
                                            <button id=<%=bt_id2%> class="hiddenBt1" onclick="saveTheChange(<%=i%>,<%=products.get(i).getId()%>)" style="width: auto" >确定</button>
                                            <button id=<%=bt_id3%> class="hiddenBt" onclick="cancelTheChange(<%=i%>,<%=products.get(i).getPrice()%>,<%=products.get(i).getReserve()%>)" style="width: auto">取消</button>
                                        </td>
                                    </tr>
                                    <%}}}%>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                </div>
                    <div class="col-md-2"></div>
            </div>
        </div>
        </div>
    </rapid:override>
    <input id="inputAdd" type="submit" value="新增一个商品" class="back-to-top-return" onclick="addProduct()">
        <input type="hidden" id="modifyProductInfo" value='' name="modifyProductInfo">
        <input type="hidden" id="lineNum" value="" name="lineNum">
    <%@ include file="salesmanMenuBarIndex.jsp"%>
</body>
</html>
